package openadmin.model.control;

/**
 * <desc>class that stores the basic information of access</desc>
 * <responsibility>Represents all the access for users</responsibility>
 * <coperation>Interface Base - Class User - Class Role - Class Entity</coperation>
 * @version  0.1
 * Created 10-05-2008
 * Modifier 15-04-2009 
 * Author Alfred Oliver
*/

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

import openadmin.dao.Base;

@Entity
@Table(name = "access", schema = "control", uniqueConstraints = @UniqueConstraint(columnNames =  { "person", "entityadm", "role" }))
public class Access implements Base, java.io.Serializable {

	/** attribute that contain the identifier*/
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)	
	private Integer id;
	
	/** attribute that contains the access description*/		
	@Length(max = 60)
	private String description;
	
	/** Transient attribute that means that the system should make a log on any JPA operation of this class*/
	@Transient
	private boolean debuglog = true;
	
	/** attribute that contain the relationship with role*/
	@ManyToOne
	@JoinColumn(name = "role", nullable= false)
	private Role role;
	
	/** attribute that contain the relationship with user*/
	@ManyToOne
	@JoinColumn(name = "person", nullable= false)
	private User person;	
	
	/** attribute that contain the relationship with entity*/
	@ManyToOne
	@JoinColumn(name = "entityadm", nullable= false)
	private EntityAdm entityAdm;	
	
	/** Transient attribute that means that the system should make a historic on any JPA operation of this class*/
	@Transient
	boolean historiclog = false;

	/**
	 * Constructor of the class Access.
	 * without parameters
	 */
	public Access() {
	}

	/**
	 * Constructor of the class Access.
	 * @param pDescription is the description
	 */
	public Access(String pDescription) {
		
		this.description = pDescription;
			}
	/**
	 * Constructor of the class Access.
	 * @param pRole, is the role
	 * @param pUser, is the user
	 */
	public Access(Role pRole, User pUser) {
		
		this.role = pRole;
		this.person = pUser;
	}
	
	/** Getters and setters*/	
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer pId) {
		this.id = pId;
	}
	
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String pDescription) {
		
		this.description = pDescription;
	}
	
	public Role getRole() {
		return this.role;
	}

	public void setRole(Role pRole) {
		this.role = pRole;
	}
	
	public User getUser() {
		return this.person;
	}

	public void setUser(User user) {
		this.person = user;
	}
	
	public EntityAdm getEntity() {
		return entityAdm;
	}

	public void setEntity(EntityAdm pEntity) {
		this.entityAdm = pEntity;
	}
	
	public boolean getDebugLog() {
		
		return debuglog;
	}
	
	public void setDebugLog(boolean pDebuglog) {
		
		debuglog = pDebuglog;
	
	}
	
	public boolean getHistoricLog() {
		return historiclog;
	}

	public void setHistoricLog(boolean historiclog) {
		this.historiclog = historiclog;
	}

	@Override
	public String toString(){
		 
		 return description;
	}
	
}
